<template>
    <div>
        <h1>修改</h1>
        <el-form :inline="true" :model="subjects" class="demo-form-inline">
   <label for="" class="sub">专业
        <input type="text" v-model="subjects.name"  class="sub2">
  </label>
  <el-form-item>
    <el-button type="primary" @click="onSubmit">确认修改</el-button>
  </el-form-item>
</el-form>
    </div>
</template>

<script>
import {createNamespacedHelpers} from 'vuex'
  const {mapActions}=  createNamespacedHelpers('subject')
export default {
      data() {
            return {
                 subjects:{
                     
                 }
            }
        },
        created() {
            console.log(this.$route.params.id);
            this.getOne()
        },
      
           methods: {
               ...mapActions(['getOneSubjectAsync']),
               ...mapActions(['updataSubjectAsync']),
             async  getOne(){   
                        const data=   await  this.getOneSubjectAsync({_id:this.$route.params.id})
                         this.subjects={...data.data}
               },
           async onSubmit() {
             const data=   await  this.updataSubjectAsync(this.subjects)  
             if(data.code){
                this.$message({
                message: '修改成功',
                type: 'success'
              });
                this.$router.push('/home/subject')
             }
                
      },
        
    }
}
</script>

<style scoped>  
.sub{
    font-size: 20px;
}
.sub2{
    height: 23px;
    margin-right: 10px;
}
</style>